<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="设备编号" prop="indexCode">
      <el-input v-model="dataForm.indexCode" placeholder="设备编号"></el-input>
    </el-form-item>
    <el-form-item label="温度 " prop="temp">
      <el-input v-model="dataForm.temp" placeholder="温度 "></el-input>
    </el-form-item>
    <el-form-item label="湿度" prop="humidity">
      <el-input v-model="dataForm.humidity" placeholder="湿度"></el-input>
    </el-form-item>
    <el-form-item label="风机运行" prop="windSwitch">
      <el-input v-model="dataForm.windSwitch" placeholder="风机运行"></el-input>
    </el-form-item>
    <el-form-item label="加热器" prop="warmer">
      <el-input v-model="dataForm.warmer" placeholder="加热器"></el-input>
    </el-form-item>
    <el-form-item label="加湿器" prop="humidifier">
      <el-input v-model="dataForm.humidifier" placeholder="加湿器"></el-input>
    </el-form-item>
    <el-form-item label="抽湿机" prop="dehumidifier">
      <el-input v-model="dataForm.dehumidifier" placeholder="抽湿机"></el-input>
    </el-form-item>
    <el-form-item label="风机过载" prop="fanOverload">
      <el-input v-model="dataForm.fanOverload" placeholder="风机过载"></el-input>
    </el-form-item>
    <el-form-item label="气流流动故障" prop="airFlowFault">
      <el-input v-model="dataForm.airFlowFault" placeholder="气流流动故障"></el-input>
    </el-form-item>
    <el-form-item label="压缩机高压" prop="highPressure">
      <el-input v-model="dataForm.highPressure" placeholder="压缩机高压"></el-input>
    </el-form-item>
    <el-form-item label="压缩机低压" prop="lowPressure">
      <el-input v-model="dataForm.lowPressure" placeholder="压缩机低压"></el-input>
    </el-form-item>
    <el-form-item label="烟感告警" prop="smokeAlarm">
      <el-input v-model="dataForm.smokeAlarm" placeholder="烟感告警"></el-input>
    </el-form-item>
    <el-form-item label="漏水告警" prop="waterWarn">
      <el-input v-model="dataForm.waterWarn" placeholder="漏水告警"></el-input>
    </el-form-item>
    <el-form-item label="加湿器故障" prop="lackWater">
      <el-input v-model="dataForm.lackWater" placeholder="加湿器故障"></el-input>
    </el-form-item>
    <el-form-item label="加湿器电流过大" prop="excessiveCurrent">
      <el-input v-model="dataForm.excessiveCurrent" placeholder="加湿器电流过大"></el-input>
    </el-form-item>
    <el-form-item label="水温度过高" prop="tempTooHigh">
      <el-input v-model="dataForm.tempTooHigh" placeholder="水温度过高"></el-input>
    </el-form-item>
    <el-form-item label="滤网堵塞" prop="screenClog">
      <el-input v-model="dataForm.screenClog" placeholder="滤网堵塞"></el-input>
    </el-form-item>
    <el-form-item label="压缩机过载" prop="compressorOverload">
      <el-input v-model="dataForm.compressorOverload" placeholder="压缩机过载"></el-input>
    </el-form-item>
    <el-form-item label="加热器超时" prop="heaterTimeout">
      <el-input v-model="dataForm.heaterTimeout" placeholder="加热器超时"></el-input>
    </el-form-item>
    <el-form-item label="温度当前值" prop="currentVal">
      <el-input v-model="dataForm.currentVal" placeholder="温度当前值"></el-input>
    </el-form-item>
    <el-form-item label="温度上限值" prop="upVal">
      <el-input v-model="dataForm.upVal" placeholder="温度上限值"></el-input>
    </el-form-item>
    <el-form-item label="温度下限值" prop="downVal">
      <el-input v-model="dataForm.downVal" placeholder="温度下限值"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()" v-if="canSubmit">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
    import {getObj, addObj, putObj} from '@/api/hik/hikcdcaircondition'

    export default {
    data () {
      return {
        visible: false,
        canSubmit: false,
        dataForm: {
          id: 0,
          indexCode: '',

          temp: '',

          humidity: '',

          windSwitch: '',

          warmer: '',

          humidifier: '',

          dehumidifier: '',

          fanOverload: '',

          airFlowFault: '',

          highPressure: '',

          lowPressure: '',

          smokeAlarm: '',

          waterWarn: '',

          lackWater: '',

          excessiveCurrent: '',

          tempTooHigh: '',

          screenClog: '',

          compressorOverload: '',

          heaterTimeout: '',

          currentVal: '',

          upVal: '',

          downVal: '',

          createTime: '',

          updateTime: '',

          updateBy: '',

          delFlag: '',

        },
        dataRule: {
          indexCode: [
            { required: true, message: '设备编号不能为空', trigger: 'blur' }
          ],

          temp: [
            { required: true, message: '温度 不能为空', trigger: 'blur' }
          ],

          humidity: [
            { required: true, message: '湿度不能为空', trigger: 'blur' }
          ],

          windSwitch: [
            { required: true, message: '风机运行不能为空', trigger: 'blur' }
          ],

          warmer: [
            { required: true, message: '加热器不能为空', trigger: 'blur' }
          ],

          humidifier: [
            { required: true, message: '加湿器不能为空', trigger: 'blur' }
          ],

          dehumidifier: [
            { required: true, message: '抽湿机不能为空', trigger: 'blur' }
          ],

          fanOverload: [
            { required: true, message: '风机过载不能为空', trigger: 'blur' }
          ],

          airFlowFault: [
            { required: true, message: '气流流动故障不能为空', trigger: 'blur' }
          ],

          highPressure: [
            { required: true, message: '压缩机高压不能为空', trigger: 'blur' }
          ],

          lowPressure: [
            { required: true, message: '压缩机低压不能为空', trigger: 'blur' }
          ],

          smokeAlarm: [
            { required: true, message: '烟感告警不能为空', trigger: 'blur' }
          ],

          waterWarn: [
            { required: true, message: '漏水告警不能为空', trigger: 'blur' }
          ],

          lackWater: [
            { required: true, message: '加湿器故障不能为空', trigger: 'blur' }
          ],

          excessiveCurrent: [
            { required: true, message: '加湿器电流过大不能为空', trigger: 'blur' }
          ],

          tempTooHigh: [
            { required: true, message: '水温度过高不能为空', trigger: 'blur' }
          ],

          screenClog: [
            { required: true, message: '滤网堵塞不能为空', trigger: 'blur' }
          ],

          compressorOverload: [
            { required: true, message: '压缩机过载不能为空', trigger: 'blur' }
          ],

          heaterTimeout: [
            { required: true, message: '加热器超时不能为空', trigger: 'blur' }
          ],

          currentVal: [
            { required: true, message: '温度当前值不能为空', trigger: 'blur' }
          ],

          upVal: [
            { required: true, message: '温度上限值不能为空', trigger: 'blur' }
          ],

          downVal: [
            { required: true, message: '温度下限值不能为空', trigger: 'blur' }
          ],

          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],

          updateTime: [
            { required: true, message: '更新时间不能为空', trigger: 'blur' }
          ],

          updateBy: [
            { required: true, message: '操作人不能为空', trigger: 'blur' }
          ],

          delFlag: [
            { required: true, message: '0 正常 1或者其他删除不能为空', trigger: 'blur' }
          ],

        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0;
        this.visible = true;
        this.canSubmit = true;
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            getObj(this.dataForm.id).then(response => {
                this.dataForm = response.data.data
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.canSubmit = false;
            if (this.dataForm.id) {
                putObj(this.dataForm).then(data => {
                    this.$notify.success('修改成功')
                    this.visible = false
                    this.$emit('refreshDataList')
                }).catch(() => {
                    this.canSubmit = true;
                });
            } else {
                addObj(this.dataForm).then(data => {
                    this.$notify.success('添加成功')
                    this.visible = false
                    this.$emit('refreshDataList')
                }).catch(() => {
                    this.canSubmit = true;
                });
            }
          }
        })
      }
    }
  }
</script>
